#!/bin/sh
SRCDIR=$1
shift
HEAD=$1
shift
TAIL=$1
shift
rm -f $HEAD $TAIL
echo "#if HAVE_GNUC_ATTRIBUTE" >> $TAIL
cat "$@" | grep '^Fc[^ ]* *(' | sed -e 's/ *(.*$//' |
while read name; do
	case $name in
	FcCacheDir|FcCacheSubdir)
		;;
	*)
		alias="IA__$name"
		hattr='__attribute((visibility("hidden")))'
		echo "extern __typeof ($name) $alias $hattr;" >> $HEAD
		echo "#define $name $alias" >> $HEAD
		grep -l '^'$name'[ (]' "$SRCDIR"/*.c | sed -n 1p | sed -e 's/^.*\/\([^.]*\)\.c/#ifdef __\1__/' >> $TAIL
		echo "#undef $name" >> $TAIL
		cattr='__attribute((alias("'$alias'"), visibility("default")))'
		echo "extern __typeof ($name) $name $cattr;" >> $TAIL
		echo "#endif" >> $TAIL
		;;
	esac
done
echo "#endif" >> $TAIL
